<?php
require_once dirname(__FILE__) . '/../../../bootstrap.unit.php';
require_once FORAGE_APP_PATH . '/features/faceting/FacetingQueryFeature.php';

class FacetingQueryFeatureTest extends ForageUnitTestCase
{
  private $query;

  public function setUp()
  {
    $this->query = new ForageQuery();
    $this->query->addFeature(new ForageFacetingQueryFeature());
  }

  public function tearDown()
  {
    unset($this->query);
  }

  public function testAddingBasicFacets()
  {
    $this->query->setFacetFields(array('length', 'colour'));
    $this->assertEquals($this->query->getFacetFields(), array('length', 'colour'));
  }

  public function testAddingAFacetFilter()
  {
    $this->query->setFacetFields(array('length', 'colour'));
    $this->query->addFacetFilter('colour', 'blue');
    $this->assertEquals($this->query->getFacetFilters('colour'), array('blue'));
  }
  
  /**
   * @expectedException ForageException
   */
  public function testAddingAFacetFilterFailsForNonSetFilter()
  {
    $this->query->addFacetFilter('colour', 'blue');
  }
}
